package com.dongbo.recorder.screenrecord.ui.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.CountDownTimer;
import android.util.Log;

import com.dongbo.recorder.screenrecord.AppLpds;
import com.dongbo.recorder.screenrecord.base.BaseActivity;
import com.dongbo.recorder.screenrecord.R;
import com.gyf.immersionbar.ImmersionBar;

/**
 * @author GuoZi
 * @date :2020/5/3 13:09
 * @description:
 */
public class WelcomeActivity extends BaseActivity {


    @Override
    protected int getLayout() {
        return R.layout.activity_welcome;
    }

    @Override
    protected void initView() {
        ImmersionBar.with(this).statusBarColor(R.color.white).transparentStatusBar().transparentNavigationBar().init();
    }

    @SuppressLint("CheckResult")
    @Override
    protected void initData() {
        rxPermissions
                .requestEach(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                        Manifest.permission.CAMERA,
                        Manifest.permission.RECORD_AUDIO)
                .subscribe(permission -> { // will emit 2 Permission objects
                    if (permission.granted) {
                        // `permission.name` is granted !
                    } else if (permission.shouldShowRequestPermissionRationale) {
                        // Denied permission without ask never again
                        Log.d("gstory","不再询问");
                    } else {
                        // Denied permission with ask never again
                        // Need to go to the settings
                    }
                    //最后一个权限校验完成进入首页
                    if(permission.name.equals(Manifest.permission.RECORD_AUDIO)){
                        timer.start();
                    }
                    Log.d("gstory",permission.name);
                });
    }

    @Override
    protected void initListener() {

    }

    //倒计时三秒进入首页
    CountDownTimer timer = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            Log.d("welcome",millisUntilFinished+"");
        }

        public void onFinish() {
            if(AppLpds.getMySp().getIsFirst()){
                startActivity(new Intent(WelcomeActivity.this, FirstActivity.class));
            }else{
                startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
            }
            WelcomeActivity.this.finish();
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}
